package com.twotwoshop.service.goods.controller;


import com.twotwoshop.commom.annotation.BrowsingHistoryAnnotation;
import com.twotwoshop.domin.common.dtos.ResponseResult;
import com.twotwoshop.domin.goods.dtos.GoodsSearchDto;
import com.twotwoshop.domin.goods.dtos.ProductDto;
import com.twotwoshop.service.goods.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
@RequiredArgsConstructor
public class ProductController {

    private final ProductService productService;

    /**
     * 物品发布
     *
     * @return
     */
    @PostMapping("/publish")
    public ResponseResult publish(@RequestBody ProductDto productDto) {
        return productService.publishProduct(productDto);
    }



    /**
     * 获取我的发布商品
     * @return
     */
    @PostMapping("/my/list")
    public ResponseResult listProducts(@RequestBody GoodsSearchDto goodsSearchDto) {
        return productService.listProducts(goodsSearchDto);
    }


    /**
     * 根据用户id获取发布商品
     * @return
     */
    @PostMapping("/byUserid/list/{userId}")
    public ResponseResult listProductsByUserId(@PathVariable Long userId) {
        return productService.listProductsByUserId(userId);
    }



    /**
     * 获取全部商品
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listProductsAll(@RequestBody GoodsSearchDto goodsSearchDto) {
        return productService.listProductsAll(goodsSearchDto);
    }


    /**
     * 订单服务获取商品详情信息
     * @return
     */
    @GetMapping("/order/{id}")
    public ResponseResult ProductById(@PathVariable("id") Long id) {
        return productService.productDetail(id);
    }


    /**
     * 获取商品详情信息
     * @return
     */
    @GetMapping("/detail/{id}")
    @BrowsingHistoryAnnotation//记录用户浏览记录
    public ResponseResult ProductDetail(@PathVariable Long id) {
        return productService.productDetail(id);
    }


    /**
     * 上下架商品
     *
     * @param productDto
     * @return
     */
    @PostMapping("/status")
    public ResponseResult updateStatus(@RequestBody ProductDto productDto) {
        return productService.updateStatus(productDto);
    }


    /**
     * 修改商品信息
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateProduct(@RequestBody ProductDto productDto) {
        return productService.updateProduct(productDto);
    }


    /**
     * 删除商品
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteProduct(@PathVariable Long id) {
        return productService.deleteProduct(id);
    }


}